import { http } from '@/untils'
import type { ResType } from './shared'

export type ChannelsItem = {
    id: number,
    name: string
}

type ChannelsRes = {
    channels: ChannelsItem[]
}

//请求频道列表
const fetchChannelAPI = () => {
    return http.request<ResType<ChannelsRes>>({
        url: '/channels'
    })
}

//请求文章列表
type ListItem = {
    art_id: string
    title: string
    aut_id: string
    comm_count: number
    pubdate: string
    aut_name: string
    is_top: number
    cover: {
        type: number
        images?: string[]
    }
}

// type ListItem = {
//     art_id: string
//   title: string
//   aut_id: string
//   comm_count: number
//   pubdate: string
//   aut_name: string
//   is_top: 0 | 1
//   cover: {
//     type: 0 | 1 | 3
//     images: string[]
//   }
// }

export type ListRes = {
    results: ListItem[]
    pre_timestamp: string
}

type reqParams = {
    channel_id: string
    timestamp: string
}

//请求文章列表
const fetchListAPI = (params: reqParams) => {
    return http.request<ResType<ListRes>>({
        url: '/articles',
        params: params
    })
}

export { fetchChannelAPI, fetchListAPI }
